<template>
	<view>
		<view class="isline"></view>
		<view class="label">
			<view class="label_text" style="margin-bottom: 20rpx;">SN码</view>
			<view class="textinput flex-between">
				<input type="text" v-model="sn" @input='inputChange' placeholder="输入SN码" placeholder-class="phone" />
				<view class="flex" style="align-items: center;">
					<view class="text2" @tap="handleScanCode">
						<image src="../../static/sweep.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="label">
			<view class="label_text">备注</view>
			<view class="textinput flex-between">
				<input type="text" v-model="remark" @input='inputChange' placeholder="输入备注" placeholder-class="phone" />
			</view>
		</view> -->
		<view class="label flex-between">
			<view class="label_text">选择分组</view>
			<view class="textinput textinput1 flex" @click="showmodel=true">
				<span class="phone" :style="activeName?'color:#333333;':''">{{activeName?activeName:'选择分组'}}</span>
				<view class="flex" style="align-items: center;">
					<image class="img2" src="../../static/goin.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="label flex-between">
			<view class="label_text">选择消耗</view>
			<view class="textinput textinput1 flex" @click="show6=true">
				<span class="phone"
					:style="moneyTypeText?'color:#333333;':''">{{moneyTypeText?moneyTypeText:'选择消耗'}}</span>
				<view class="flex" style="align-items: center;">
					<image class="img2" src="../../static/goin.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="label flex-between">
			<view class="label_text">选择位置</view>
			<view class="textinput textinput1 flex" @click="chooseLocation">
				<span class="phone phone1"
					:style="addressName?'color:#333333;':''">{{addressName?addressName:'选择位置'}}</span>
				<view class="flex" style="align-items: center;">
					<image class="img2" src="../../static/goin.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="bot">
			火豆余额：{{huomoney}}
			<!-- <span>去兑换></span> -->
		</view>
		<view class="bot" style="margin-top: 20rpx;">
			激活码数量：{{activationmoney}}
			<!-- <span>去兑换></span> -->
		</view>
		<view class="isbtn istext" @click="$u.debounce(addBind(sn), 500)">
			提交
		</view>
		<u-overlay :show="showmodel" @click="showmodel = false">
			<view class="model">
				<view class="model_name" v-for="(item,index) in GroupList" :key="index" @click="btngroup(item)">
					{{item.name}}
				</view>
				<view class="model_line"></view>
				<view class="model_name" @click="showmodel=false">取消</view>
			</view>
		</u-overlay>
		<u-picker keyName="label" :show="show6" @cancel='show6=false' @confirm="confirm6"
			:columns="columns6"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nameid: '',
				remark: '',
				logining: false,
				group: '',
				showmodel: false,
				sn: '',
				GroupList: [],
				count: '',
				activeName: '',
				activeNameid: '',
				columns6: [
					[{
							label: '火豆',
							value: 'bean',
							type: 1
						},
						{
							label: '激活码',
							value: 'activation',
							type: 2
						}
					]
				],
				huomoney: 0,
				activationmoney: 0,
				showgo: false,
				show6: false,
				moneyTypeText: '',
				latitude: '',
				longitude: '',
				addressName: ''
			}
		},
		onLoad() {
			this.getGroupList()
			//火豆
			this.$fun.ajax.post('config/recharge', {
				id: 4,
			}).then(res => {
				this.huomoney = res.data.money
			})
			//激活码
			this.$fun.ajax.post('config/recharge', {
				id: 10,
			}).then(res => {
				this.activationmoney = res.data.money
			})
		},
		methods: {
			inputChange() {
				const {
					id,
					remark,
					group
				} = this
				if (id !== '' && remark !== '') {
					this.logining = true
				} else {
					this.logining = false
				}
			},
			handleScanCode() {
				let _that = this
				//#ifdef H5
				this.$fun.msg('H5暂不支持扫码！')
				//#endif
				// #ifndef H5
				uni.scanCode({
					success: function(res) {
						_that.nameid = res.result
					}
				});
				// #endif
			},

			//选择位置
			chooseLocation() {
				let _this = this
				uni.chooseLocation({
					success: function(res) {
						// console.log('位置名称：' + res.name);
						// console.log('详细地址：' + res.address);
						// console.log('纬度：' + res.latitude);
						// console.log('经度：' + res.longitude);
						_this.latitude = res.latitude
						_this.longitude = res.longitude
						_this.addressName = res.name
					}
				});
			},
			btngroup(item) {
				this.count = item.num
				this.activeName = item.name
				this.activeNameid = item.id
			},
			async getGroupList(onlineCode = -1) {
				await this.$fun.ajax.post('butt/groupList', {
					onlineCode,
				}).then(res => {
					this.GroupList = res.data
					this.count = res.data[0].num
					this.activeName = res.data[0].name
					this.activeNameid = res.data[0].id
				})
			},
			confirm6(item) {
				this.show6 = false
				this.moneytype = item.value[0].value
				this.moneyTypeText = item.value[0].label
				this.type = item.value[0].type
			},
			addBind(sn) {
				if (this.activeNameid == null) {
					this.$fun.msg('请选择分组')
					return
				}
				if (!this.moneyTypeText) {
					this.$fun.msg('请选择消耗')
					return
				}
				if (!this.addressName) {
					this.$fun.msg('请选择位置')
					return
				}
				this.$fun.ajax.post('butt/bind', {
					sn,
					group_id: this.activeNameid,
					type: this.type,
					lng: this.longitude,
					lat: this.latitude
				}).then(res => {
					this.$fun.msg(res.msg)
					if (res.code == 1) {
						this.sn = ""
						this.$fun.jump('', 4, 1200)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.flex-between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.isline {
		width: 750rpx;
		height: 16rpx;
		background: #F5F1EE;
	}

	.label {
		width: 690rpx;
		box-sizing: border-box;
		margin: 20rpx auto 0;
		padding-top: 40rpx;
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid #EAEAEA;

		&_text {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
			line-height: 28rpx;
			text-align: left;
			font-style: normal;
		}

		.textinput {
			// width: 690rpx;
			// height: 70rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			box-sizing: border-box;
			// margin-top: 20rpx;
			align-items: center;

			.phone1 {
				width: 400rpx;
				text-align: right;
			}

			input {
				width: 580rpx;
			}

			.text1 {
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
			}

			.text2 {
				font-weight: 500;
				font-size: 28rpx;
				color: #9999FF;

				image {
					width: 28rpx;
					height: 28rpx;
				}
			}
		}

		.textinput1 {
			// width: 160rpx;
			display: flex;
		}

		.img1 {
			width: 2rpx;
			height: 40rpx;
			margin: 0 20rpx;
		}

		.img2 {
			width: 48rpx;
			height: 48rpx;
		}

		.istipcol {
			color: #999999;
		}

		.phone,
		.password {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #CCCCCC;
			text-align: left;
			font-style: normal;
		}
	}

	.istext {
		width: 690rpx;
		height: 88rpx;
		border-radius: 44rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #CCCCCC;
		line-height: 88rpx;
		text-align: left;
		font-style: normal;
		text-align: center;
		margin: 90rpx auto 0;
	}

	.isbtn {
		background: $uni-color-primary;
		color: #FFFFFF;
	}

	.model {
		width: 750rpx;
		// height: 384rpx;
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		position: fixed;
		bottom: 0;

		&_name {
			width: 750rpx;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-radius: 24rpx 24rpx 0rpx 0rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #333333;
		}

		&_line {
			width: 750rpx;
			height: 16rpx;
			background: #F1F3F6;
		}
	}

	.bot {
		font-weight: 400;
		font-size: 24rpx;
		color: #333333;
		text-align: left;
		margin-top: 40rpx;
		margin-left: 30rpx;

		span {
			color: #FB6C04;
			margin-left: 20rpx;
		}
	}
</style>